package com.swanclouds.redfish.account.domain.Oem.HuaWei;

import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.swanclouds.model.account.builder.HuaWei.HuaWeiCreateAccount;
import com.swanclouds.model.account.builder.HuaWei.HuaWeiAccountCreateBuilder;

/**
 * Oem.Huawei 创建用户
 * @author 张立强
 * @version jdk1.8.0
 */
public class HuaWeiCreateAccountConcrete implements HuaWeiCreateAccount {

    @JsonProperty("UserName")
    private String userName;

    @JsonProperty("Password")
    private String password;

    @JsonProperty("RoleId")
    private RoleId roleId;
    /**
     * 用户名，大小写字母、数字、特殊符号“-”、“_”、“@”，字母开头
     *
     * @return UserName
     */
    @Override
    public String getUserName() {
        return this.userName;
    }

    /**
     * 用户密码，长度为8到16个字符串
     *
     * @return Password
     */
    @Override
    public String getPassword() {
        return this.password;
    }

    /**
     * 用户角色，可设置的角色
     * BMC [Administrator,Operator,User,None]
     * HuaWei [Administrator,Operator,Commonuser,Noaccess,CustomRole1...]
     *
     * @return RoleId
     */
    @Override
    public String getRoleId() {
        return roleId != null ? roleId.name() : null;
    }

    enum RoleId {
        Administrator,Operator,Commonuser,Noaccess,CustomRole1,CustomRole2,CustomRole3,CustomRole4;
    }

    @Override
    public HuaWeiAccountCreateBuilder toBuilder() {
        return new HuaWeiCreateAccountConcreteBuilder();
    }

    public static HuaWeiAccountCreateBuilder builder() {
        return new HuaWeiCreateAccountConcrete().toBuilder();
    }

    public static class HuaWeiCreateAccountConcreteBuilder implements HuaWeiAccountCreateBuilder {

        HuaWeiCreateAccountConcrete m;

        HuaWeiCreateAccountConcreteBuilder () {
            this(new HuaWeiCreateAccountConcrete());
        }

        HuaWeiCreateAccountConcreteBuilder(HuaWeiCreateAccountConcrete m) {
            this.m = m;
        }

        /**
         * 用户名赋值
         *
         * @param userName 用户名
         * @return HuaWeiAccountCreateBuilder
         */
        @Override
        public HuaWeiAccountCreateBuilder UserName(String userName) {
            m.userName = userName;
            return this;
        }

        /**
         * 用户密码赋值
         *
         * @param password 密码
         * @return HuaWeiAccountCreateBuilder
         */
        @Override
        public HuaWeiAccountCreateBuilder Password(String password) {
            m.password = password;
            return this;
        }

        /**
         * 用户角色赋值
         *
         * @param roleId 用户组
         * @return HuaWeiAccountCreateBuilder
         */
        @Override
        public HuaWeiAccountCreateBuilder RoleId(String roleId) {
            m.roleId = RoleId.valueOf(roleId);
            return this;
        }

        /**
         * Creates and return the Model Entity M
         *
         * @return M instance
         */
        @Override
        public HuaWeiCreateAccount build() {
            return m;
        }

        /**
         * Creates a Builder using the param M as the default values
         *
         * @param in The Model M
         * @return Builder
         */
        @Override
        public HuaWeiAccountCreateBuilder from(HuaWeiCreateAccount in) {
            m = (HuaWeiCreateAccountConcrete) in;
            return this;
        }

        @Override
        public String toString() {
            ObjectMapper objectMapper = new ObjectMapper();
            try {
                return objectMapper.writeValueAsString(this);
            } catch (JsonProcessingException e) {
            }
            return "HuaWeiCreateAccountConcreteBuilder {" +
                    "m=" + m +
                    '}';
        }
    }

    @Override
    public String toString() {
        ObjectMapper objectMapper = new ObjectMapper();
        try {
            return objectMapper.writeValueAsString(this);
        } catch (JsonProcessingException e) {
        }
        return "HuaWeiCreateAccountConcrete {" +
                "userName='" + userName + '\'' +
                ", password='" + password + '\'' +
                ", roleId=" + roleId +
                '}';
    }
}
